package com.example.houduan.service;
import com.example.houduan.domain.Word;
import com.example.houduan.domain.WordExample;
import com.example.houduan.mapper.WordMapper;
import com.example.houduan.resp.CommonResp;
import com.example.houduan.resp.Wordlist;
import com.example.houduan.resp.Wordtext;
import com.example.houduan.utils.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class Wordservice {
    @Autowired
    public WordMapper wordMapper;
    public CommonResp list()
    {
        CommonResp commonResp = new CommonResp();
        List<Word> words= wordMapper.selectByExample(new WordExample());
        List<Wordlist> wordlists= CopyUtil.copyList(words,Wordlist.class);
        commonResp.setContent(wordlists);
        return commonResp;
    }
    public CommonResp find(int id)
    {
        CommonResp commonResp = new CommonResp();
        WordExample wordExample=new WordExample();
        WordExample.Criteria criteria=wordExample.createCriteria();
        criteria.andArticleidEqualTo(id);
        List<Word> wordlists=wordMapper.selectByExample(wordExample);
        Wordtext wordtext=CopyUtil.copy(wordlists.get(0),Wordtext.class);
        commonResp.setContent(wordtext);
        return  commonResp;
    }
}
